﻿using ClothingShopping.Data;
using ClothingShopping.Dto.AccountDto;
using ClothingShopping.IRepository;
using FreeSql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClothingShopping.Repository
{
    public class UserRepository: BaseRepository<User,int>, IUserRepository
    {
        public UserRepository(IFreeSql freeSql):base(freeSql,null,null)
        {
                
        }

        /// <summary>
        /// 自定义异步方法
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public async Task UpdataUserAsync(UserDto user)
        {
            try
            {
               await Task.Run(() =>
                {
                    base.Orm.Update<User>()
                    .Set(it => new User()
                    {
                        user_name = user.user_name,
                        SEX = user.SEX,
                        email = user.email,
                        phone = user.phone,
                        modifier = user.modifier,
                        mTime = DateTime.Now,
                        state = user.state
                    })
                    .Where(it => it.user_id == user.user_id).ExecuteAffrowsAsync();
                });
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        //在这里增加 CURD 以外的接口实现

    }
}
